{template 'admin','header'}
<script language="javascript">
function change_system(sobj)
{
	var display_3 = document.getElementById('display_3');
	var showlist_1 = document.getElementById('showlist_1');
	var showlist_2 = document.getElementById('showlist_2');
	if(sobj.checked==true)
	{
		
		display_3.style.display='block';
		showlist_1.disabled=false;
		showlist_2.disabled=false;
	}
	else
	{
		display_3.style.display='none';
		showlist_1.disabled=true;
		showlist_2.disabled=true;
	}
}
</script>
<table class="table_form" cellSpacing="1" cellPadding="0">
    <caption>{$modelinfo['name']}模型字段管理</caption>
    <tbody>
        <tr>
            <td>
                <a href="{$self_url}?action=field_add&modelid={$modelid}">添加字段</a> | <a href="{$self_url}?action=field_manage&modelid={$modelid}">管理字段</a>
            </td>
        </tr>
    </tbody>
</table>
<form method="post" name="myform" action="{$self_url}" onsubmit="r_submit(this);">
    {if $action=='field_add'}<input type="hidden" name="action" value="field_add">{else}<input type="hidden" name="action" value="field_edit">{/if}
    {if $action=='field_add'}<input type="hidden" name="data[modelid]" value="{$modelid}">{/if}
    <input type="hidden" name="modelid" value="{$modelid}">
    <input type="hidden" name="id" value="{$data['id']}">
    <input value="{$forward}" type="hidden" name="forward">
    {php $sys_check_flag = false; $sys_disable_flag = false;}
    {if isset($data)}
	    {if !empty($data['issystem'])}
	    	{php $sys_check_flag=true;}
	    {/if}
	    {php $sys_disable_flag=true;}
    {/if}
    <table class="table_form" cellSpacing="1" cellPadding="0">
        {if $action=='field_add'}<caption>添加字段</caption>{else}<caption>修改字段</caption>{/if}
        <tbody>
        	<tr>
        		<th><font color="red">*</font> <strong>是否系统字段</strong></th>
        		<td><input type="checkbox" onclick="change_system(this)" name="data[issystem]" {if $sys_check_flag==true}checked{/if} {if $sys_disable_flag==true}disabled{/if} value="1"></td>
        	</tr>
            <tr>
                <th width="25%"><font color="red">*</font> <strong>字段名</strong><br>只能由英文字母组成 </th>
                <td>{if $action=='field_add'}<input class="input_blur" value="{$data['field']}" name="data[field]" id="field">{else}<input class="input_blur" value="{$data['field']}" name="data[field]" disabled id="field">{/if}</td>
            </tr>
            <tr>
                <th><font color="red">*</font> <strong>字段别名</strong><br>例如：文章标题</th>
                <td><input class="input_blur" value="{$data['name']}" size="30" name="data[name]" id="name"></td>
            </tr>
            <tr>
                <th><strong>字段提示</strong><br>显示在字段别名下方作为表单输入提示</th>
                <td><textarea style="WIDTH: 250px; HEIGHT: 60px" id="tips" name="data[tips]">{$data['tips']}</textarea></td>
            </tr>
            <tr>
                <th><strong>字段类型</strong><br></th>
                <td>
                    <select id="formtype" name="data[formtype]">
                        {loop $fields $i $f}
                        <option value="{$i}" {if isset($data['formtype'])&&$data['formtype']==$i}selected{/if}>{$f}</option>
                        {/loop}
                    </select>
                    {if $action!="field_add"}<script>$("#formtype").attr('disabled',true)</script>{/if}
                    <script>
                        $("#formtype").change(function(){
                            var formtype = $(this).val();
                            var fieldid = "{$data['id']}";
                            $.post('{$self_url}?action=settings',{formtype:formtype,fieldid:fieldid},function(msg){
                                $("#setting").html(msg);
                            });
                        });
                        $("#formtype").trigger('change');
                    </script>
                </td>
            </tr>
            <tr>
                <th><strong>相关参数</strong><br>设置表单相关属性</th>
                <td>
                    <div id="setting">

                    </div>
                    <div id="setting_errors"></div>
                </td>
            </tr>
            <tr id="display_1">
                <th><strong>字段长度</strong><br>系统将在表单提交时检测数据长度范围是否符合要求</th>
                <td><input id="minlength" class="input_blur" value="{$data['length']}" size="5" name="data[length]"></td>
            </tr>
            <tr id="display_2">
                <th><strong>默认值</strong><br>默认值长度不能超过字段长度(此处字段长度根据字段类型的不同而有所区别)</th>
                <td><input size="5" name="data[default]" value="{$data['default']}" id="default"></td>
            </tr>
            <tr>
                <th><strong>数据校验正则</strong><br>系统将通过此正则校验表单提交的数据合法性，如果不想校验数据请留空</th>
                <td>
                    <input id="regex" class="input_blur" size="40" name="data[regex]" value="{$data['regex']}">
                    <SELECT onchange="javascript:$('#regex').val(this.value)" name="pattern_select">
                        <option selected value="">常用正则</option>
                        <option value="/^[0-9.-]+$/">数字</option>
                        <option value="/^[0-9-]+$/">整数</option>
                        <option value="/^[a-z]+$/i">字母</option>
                        <option value="/^[0-9a-z]+$/i">数字+字母</option>
                        <option value="/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/">E-mail</option>
                        <option value="/^[0-9]{5,20}$/">QQ</option>
                        <option value="/^http:\/\//">超级链接</option>
                        <option value="/^(13|15)[0-9]{9}$/">手机号码</option>
                        <option value="/^[0-9-]{6,13}$/">电话号码</option>
                        <option value="/^[0-9]{6}$/">邮政编码</option>
                    </SELECT>
                </td>
            </tr>
            <!--
            <tr>
                <th><strong>值唯一</strong></th>
                <td><input class="radio_style" value="1" type="radio" name="data[isunique]" {if !empty($data['isunique'])}checked{/if}> 是 <input class="radio_style" value="0"  type="radio" name="data[isunique]" {if empty($data['isunique'])}checked{/if}> 否</td>
            </tr>
            -->
            <tr>
                <th><strong>可以为空</strong></th>
                <td><input class="radio_style" value="1"  type="radio" name="data[isempty]" {if !empty($data['isempty'])}checked{/if}> 是 <input class="radio_style" value="0" type="radio" name="data[isempty]" {if empty($data['isempty'])}checked{/if}> 否</td>
            </tr>
            <tr>
                <th><strong>在信息编辑显示</strong></th>
                <td><input class="radio_style" value="1"  type="radio" name="data[showedit]" {if !empty($data['showedit'])}checked{/if}> 是 <input class="radio_style" value="0" type="radio" name="data[showedit]" {if empty($data['showedit'])}checked{/if}> 否</td>
            </tr>
            {if $sys_check_flag==true || $sys_disable_flag==false}
            <tr id="display_3" {if $sys_check_flag==false} style="display:none;"{/if}>
                <th><strong>在信息列表中显示</strong></th>
                <td><input class="radio_style" {if $sys_check_flag==false}disabled{/if} id="showlist_1" value="1" type="radio" name="data[showlist]" {if !empty($data['showlist'])}checked{/if}> 是 <input id="showlist_2" {if $sys_check_flag==false}disabled{/if} class="radio_style" value="0" type="radio" name="data[showlist]" {if empty($data['showlist'])}checked{/if}> 否</td>
            </tr>
            {/if}
            <tr>
                <th><strong>在内容页中显示</strong></th>
                <td><input class="radio_style" value="1" type="radio" name="data[showpage]" {if !empty($data['showpage'])}checked{/if}> 是 <input class="radio_style" value="0" type="radio" name="data[showpage]" {if empty($data['showpage'])}checked{/if}> 否</td>
            </tr>
            <tr>
                <th></th>
                <td><input class="button_style" value=" 确定 " type="submit" name="submitform"> &nbsp; <input class="button_style" value=" 返回 " type="button" name="back" onclick="window.location='{HTTP_REFERER}'"> </td>
            </tr>
        </tbody>
    </table>
</form>
{template 'admin','footer'}
